package cn.e4j.modular.api.controller;

import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.ErrorResponseData;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.core.reqres.response.SuccessResponseData;
import cn.e4j.modular.api.service.WdbjService;
import cn.e4j.modular.system.entity.SysUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yuan_rz on 2018/04/17.
 */
@RestController
@RequestMapping("api/wx/wdbj")
public class WdbjController {
    private static Logger logger = LoggerFactory.getLogger(WdbjController.class);

    @Autowired
    private WdbjService wdbjService;

    /**
     * 获取配件列表
     *
     * @return
     */
    @RequestMapping(value = "getPartListData")
    public ResponseData getPartListData(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = new ArrayList<Dto>();
        SysUser currentUser = wapper.getSysUser();
        try {
            inDto.put("GWAKENT", inDto.getString("ENT"));
            inDto.put("GWAA001", currentUser.getACCOUNT());
            inDto.put("LANG", "2");
            list = wdbjService.getPartListData(wapper.getPage(),inDto);
        } catch (Exception e) {
            e.printStackTrace();
            return new ErrorResponseData("服务器出小差了");
        }
        return new SuccessResponseData(list);
    }

    /**
     * 获取配件列表
     *
     * @return
     */
    @RequestMapping(value = "getMmrdData")
    public ResponseData getMmrdData(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = new ArrayList<Dto>();
        try {
            inDto.put("MMRDENT", inDto.getString("ENT"));
            list = wdbjService.getMmrdData(wapper.getPage(),inDto);
        } catch (Exception e) {
            e.printStackTrace();
            return new ErrorResponseData("服务器出小差了");
        }
        return new SuccessResponseData(list);
    }

    /**
     * 配件申请提交
     *
     * @return
     */
    @RequestMapping(value = "savePjsq")
    public ResponseData saveBjsq(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        try {
            wdbjService.savePjsq(wapper.getSysUser(),inDto);
        } catch (Exception e) {
            e.printStackTrace();
            return new ErrorResponseData("服务器出小差了");
        }
        return new SuccessResponseData();
    }
}
